/*
 * Двоичная вставка
 */

#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef DEBUG
# define debug_fprintf(x)	fprintf x
#else
# define debug_fprintf(x)	((void) 0)
#endif

#define S_assert(st) ((st)?((void)0):(void)fprintf(stderr,"Assertion (soft) \"%s\" in %s:%s():%d: failed.\n",#st,__FILE__,__func__,__LINE__))

/* autoarray */
struct vector {
	char *data;
	size_t _elem_size;

	int n;
	int _max;
};

/* {{{ function prototypes */
/* memory allocation wrappers */
void *s_calloc(size_t n, size_t size);
void *s_malloc(size_t size);
void *s_realloc(void *oldptr, size_t newsize);
/* }}} */

/* {{{ memory allocation wrappers */
extern void *s_calloc(size_t n, size_t size)
{
	void *ptr;
	ptr = calloc(n, size);
	assert(ptr != NULL);
	if (ptr == NULL) {
		fprintf(stderr, "%s(): out of memory, failed to allocate %lu bytes\n",
				__func__, n * size);
		abort();
	}
	return ptr;
}

extern void *s_malloc(size_t size)
{
	void *ptr;
	ptr = malloc(size);
	assert(ptr != NULL);
	if (ptr == NULL) {
		fprintf(stderr, "%s(): out of memory, failed to allocate %lu bytes\n",
				__func__, size);
		abort();
	}
	return ptr;
}

extern void *s_realloc(void *oldptr, size_t newsize)
{
	void *newptr;
	newptr = realloc(oldptr, newsize);
	if (newptr == NULL) {
		fprintf(stderr, "%s(): out of memory, "
				"failed to realloc %p for new size of %lu bytes\n",
				__func__, oldptr, newsize);
		abort();
	}
	return newptr;
}
/* }}} */

/* {{{ autoarray */
extern struct vector *
vector__new(size_t elem_size, int p)
{
	struct vector *v = NULL;

	if (p < 0)
		p = 0;

	v = (struct vector *) s_malloc(sizeof *v);
	v->_max = 1 << p;
	v->_elem_size = elem_size;
	v->n = 0;
	v->data = (char *) s_calloc((size_t) v->_max, v->_elem_size);

	return v;
}

extern int
vector__append(struct vector *v, const void *app)
{
	int ret = 0;

	if (v == NULL) {
		fprintf(stderr, "%s(): received NULL ptr, not doing anything (-1)\n",
				__func__);
		return -1;
	}

	if (v->_max == 0) {
		/* weird input, fix it */
		ret |= 2;
		debug_fprintf((stderr, "%s(): v->_max is 0, which means that your "
					"autoarray (v=%p) is messed up. trying to fix this.\n",
					__func__, (void*) v));
		if (v->_elem_size == 0) {
			ret |= 4;
			fprintf(stderr, "%s(): can't fix this mess, bailing out (%d)\n",
					__func__, ret);
			return ret;
		} else {
			v->_max = 1;
			v->n = 0;
			v->data = (char *) s_calloc((size_t) v->_max, v->_elem_size);
		}
	}

	if (v->n + 1 >= v->_max) {
		v->data = (char *) s_realloc(v->data, v->_elem_size * (v->_max *= 2));
	}
	memcpy(v->data + (v->n++) * v->_elem_size, app, v->_elem_size);

	return ret;
}

extern char *
vector__get_by_idx(struct vector *v, const int idx)
{
	if (v == NULL) {
		fprintf(stderr, "%s(): received NULL ptr, not doing anything (NULL)\n",
				__func__);
		return NULL;
	}

	if (v->_elem_size == 0) {
		fprintf(stderr, "%s(): whoah, looks like your vector is messed up big time (NULL)\n",
				__func__);
		return NULL;
	}

	if (idx < 0 || idx >= v->n) {
		fprintf(stderr, "%s(): index out of range %d (v->n=%d)\n",
				__func__, idx, v->n);
		return NULL;
	}

	return v->data + (idx) * v->_elem_size;
}

extern int
vector__cleanup(struct vector *v)
{
	int ret = 0;

	if (v == NULL) {
		fprintf(stderr, "%s(): received NULL ptr, not doing anything (-1)\n",
				__func__);
		return -1;
	}

	if (v->_max > 0) {
		v->_max = v->n = 0;
		free(v->data);
		v->data = NULL;
	} else {
		ret |= 1;
	}

	/* TODO: improve logic */
	debug_fprintf((stderr, "%s(): freeing v=%p\n", __func__, (void*) v));
	free(v);

	return ret;
}
/* }}} */

/* {{{ mergesort (with copy array optimization) */
static void
mergesort__merge(void *p1, size_t nmemb, size_t size,
		int (*cmpf)(const void *, const void *),
		void *p2, const int depth,
		size_t L, size_t M, size_t R)
{
	register char *base, *cpybuf;
	size_t i = L, j = M + 1;
	register size_t s = 0; /* points to where we will place next element */

	if (depth & 1)
		base = p1, cpybuf = p2;
	else
		base = p2, cpybuf = p1;

	while (i <= M && j <= R) {
		if (cmpf(base + i * size, base + j * size) <= 0) {
			if (i <= M) {
				memcpy(cpybuf + s*size, base + i*size, size);
				s++;
				i++;
			} else if (j <= R) {
				memcpy(cpybuf + s*size, base + j*size, size);
				s++;
				j++;
			}
		} else {
			if (j <= R) {
				memcpy(cpybuf + s*size, base + j*size, size);
				s++;
				j++;
			} else if (i <= M) {
				memcpy(cpybuf + s*size, base + i*size, size);
				s++;
				i++;
			}
		}
	}

	/*
	 * let's see how this works
	 */
	while (i <= M)
		memcpy(cpybuf + (s++) * size, base + (i++) * size, size);
	while (j <= R)
		memcpy(cpybuf + (s++) * size, base + (j++) * size, size);
}

static void
mergesort__main(void *base, size_t nmemb, size_t size,
		int (*cmpf)(const void *, const void *),
		void *cpybuf, const int depth,
		size_t L, size_t R)
{
	size_t M = (L + R) / 2;

	if (L < R) {
		mergesort__main(base, nmemb, size, cmpf, cpybuf, depth + 1, L, M);
		mergesort__main(base, nmemb, size, cmpf, cpybuf, depth + 1, M + 1, R);
		mergesort__merge(base, nmemb, size, cmpf, cpybuf, depth, L, M, R);
	}
}

extern void
mergesort(void *base, size_t nmemb, size_t size,
		int (*cmpf)(const void *, const void *))
{
	void *cpybuf;

	cpybuf = s_malloc(nmemb * size);
	memcpy(cpybuf, base, nmemb * size);
	mergesort__main(base, nmemb, size, cmpf, cpybuf, 0,
			0UL, nmemb - 1UL);
	free(cpybuf);
}
/* }}} */

/* {{{ bsearch */
size_t
binsearchT(const void *key, const void *pbase, size_t nmemb, size_t size,
		int (*cmpf)(const void *, const void *))
{
	const char *base = (const char *) pbase;
	size_t left = 0,
	       right = nmemb,
	       mid;
	register int cmpres;

	assert(key != NULL);
	assert(pbase != NULL);
	assert(cmpf != NULL);

	while (left < right) {
		mid = (left + right) / 2;
		cmpres = (*cmpf)(key, base + mid * size);
		if (cmpres < 0)
			right = mid;
		else
			left = mid + 1;
	}

	return left;
}
/* }}} */

int
intcmp(const void *p1, const void *p2)
{
	const int *a = p1, *b = p2;

	assert(p1 != NULL);
	assert(p2 != NULL);

	if (*a < *b) {
		debug_fprintf((stderr, "%d < %d\t(-1)\n", *a, *b));
		return -1;
	} else if (*a > *b) {
		debug_fprintf((stderr, "%d > %d\t(1)\n", *a, *b));
		return 1;
	} else {
		debug_fprintf((stderr, "%d = %d\t(0)\n", *a, *b));
		return 0;
	}
}

int
main(int argc, char **argv)
{
	int n, m;
	int *a, b;
	int i;
	register int t;

	scanf("%d", &n);
	a = s_malloc(n * sizeof *a);
	for (i = 0; i < n; i++)
		scanf("%d", a + i);
	scanf("%d", &m);
	for (i = 0; i < m; i++) {
		scanf("%d", &b);
		t = (int) binsearchT(&b, a, n, sizeof a[0], intcmp);
		debug_fprintf((stderr, "%4d: t=%d\n", i, t));
		while (t < n && b >= a[t])
			t++;
		printf("%d\n", t);
	}

	free(a);
	return 0;
}
